#include "sTRModule.h"
#include "sEngine.h"
#include "sEngineItem.h"
#include "sTexture.h"
#include "sGui.h"

namespace sgui
{
namespace res
{    

void sTextureResourceModule::load(const db::Record &file)
{
	sNamedObject::load(file);
	m_rect.load(file[L"rect"]);
}

void sTextureResourceModule::save(db::Record &file) const
{
	sNamedObject::save(file);
	m_rect.save(file[L"rect"]);
}

void sTextureResourceModule::clear()
{
	m_rect.clear();
}
		
math::sRectf& sTextureResourceModule::getRect()
{
	return m_rect;
}

sLinkTo<preset::sTexturePreset>& sTextureResourceModule::getPreset()
{
	return m_preset;
}

void sTextureResourceModule::draw(engine::sDrawStack& drawStack) const
{
	const preset::sTexturePreset *pres = m_preset.get();

	if (pres)
	{
		const engine::sTexture *tex = (const engine::sTexture*)pres->getEngineItem();
		if (tex)
		{
			tex->drawClip(math::sRectf(math::sPointf(), m_rect.getSize()), m_rect);
		}
	}
}

#ifdef _EDITOR
void sTextureResourceModule::exportRTTI(rtti::sInfoList& list)
{
	REGISTER_RTTI(L"Data", TEXT, NEW_RTTI_CLASS_PARAMETER(m_rect));
}

#endif

sTextureResourceModule::sTextureResourceModule(sGUI& gui, const std::wstring& name) :
	sNamedObject(gui, name),
	m_preset(gui)
{

}

sTextureResourceModule::~sTextureResourceModule()
{

}

	

};
};
